#!/bin/bash

#
# Copyright 2009 Lee Kemp
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# 	http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


############################################################
# Variables
# Set JAVA_EXE and APPLICATION_HOME here
############################################################

export APPLICATION_HOME=.
export LIB_HOME="%APPLICATION_HOME%/lib"
export USER_LIB_HOME="%APPLICATION_HOME%/user/lib"
export JAVA_EXE=java
export JAVA_OPTS=
export _MAINCLASS=org.outburstframework.runner.OutburstTestRunner

############################################################
# Header
############################################################

echo ............................................................
echo Outburst framework core (test runner)
echo outburstframework.org
echo ............................................................

############################################################
# functions
############################################################

function start() {
	# if [ "$1" = "" ]; then
	#	printHelp
	# else
		setClasspath
		startRunner
	# fi
}

function startRunner() {
	export __COMMAND=$JAVA_EXE -classpath "$_CLASSPATH" $JAVA_OPTS $_MAINCLASS  $*
	echo ............................................................
	echo Starting runner
	echo $_MAINCLASS
	echo $__COMMAND
	echo ............................................................
	$__COMMAND
}

function setClasspath() {
	echo Setting the classpath using $LIB_HOME and $USER_LIB_HOME

	for i in $LIB_HOME/*; do
		echo adding $i to CLASSPATH
		CLASSPATH=$i:$CLASSPATH
		export CLASSPATH
	done;
	
	for i in USER_LIB_HOME/*; do
		echo adding $i to CLASSPATH
		CLASSPATH=$i:$CLASSPATH
		export CLASSPATH
	done;
}

function printHelp() {
	echo ............................................................
	echo Usage
	echo outburst-runner.sh CLASS_NAME RUN_TIME RESULT_INTERVAL RUNS
	echo outburst-runner.sh com.kumkee.outburst.example.MapTest 3600000 10000 1000
	echo CLASS_NAME=The fully qualified name of the test class
	echo RUN_TIME=The amount of time to run the test in milliseconds
	echo RESULT_INTERVAL=Time between result logging in milliseconds
	echo RUNS=The number of times to run the tests
	echo ............................................................
}

function end() {
}

############################################################
# Main
############################################################

clear

# Change the amount of allowed open files in linux
# ulimit -n 10000

start

end




